Skip to content

Map OpenMP reduction variables explicitly on NVHPC - #2018

Merged
sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:fix/nvhpc-omp-reduction-map
Oct 11, 2026
Merged

sbryngelson merged 1 commit into
MFlowCode:masterfrom
sbryngelson:fix/nvhpc-omp-reduction-map

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Since #1821, the Phoenix NVHPC gpu-omp lane intermittently fails
3D -> 2 MPI Ranks -> IBM Sphere (AFBACA70) and
3D -> 2 MPI Ranks -> IBM Moving Sphere -> ib_neighborhood_radius=2 (2440B4AE)
with "call to cuMemcpyDtoHAsync returned error 700 (CUDA_ERROR_ILLEGAL_ADDRESS)"
at step 1, on master and unrelated PRs. It fails whenever the two ranks see
more than one GPU, so rank 1's OpenMP default device is 1; it passes when they
share a GPU, which is why retries sometimes succeed.

compute-sanitizer pins it to an out-of-bounds atomic at the end of the
s_ibm_correct_state ghost-point loop (m_ibm.fpp:598, launched at :345): the
reduction(+:n_not_converged, n_ill_posed) that #1821 added. A standalone
nvfortran 25.11 program reproduces it outside MFC: a multi-variable scalar
reduction on a target teams loop run on default device 1 fails with
CUDA_ERROR_ILLEGAL_ADDRESS when device 0's CUDA context is current (as UCX
leaves it after MPI_Init) and with CUDA_ERROR_INVALID_CONTEXT when none is.
NVHPC allocates the implicitly mapped reduction storage in the current CUDA
context instead of on the default device. Mapping the reduction variables
explicitly with map(tofrom:) avoids it; m_bubbles_EL already pairs its two
reductions with copy= of the same variables.

Emit map(tofrom:) for the reduction variables in OMP_PARALLEL_LOOP on NVHPC,
skipping any already listed in copy. This covers all six reduction loops
without one (m_chemistry, m_collisions, m_data_output, m_ibm,
m_pressure_relaxation, m_time_steppers). Other compilers and OpenACC are
unchanged: the Fypp output is identical apart from those six directives.

Verified on 3x A100 with NVHPC 25.11 (--gpu mp, MPI, release):

  • master: the six 2 MPI Ranks tests with -g 0 1 give 4 passed, 2 failed
    (AFBACA70, 2440B4AE: memory access fault by GPU); direct runs with both
    GPUs visible fault 5 of 5 times.
  • this change: 6 of 6 pass, three times; the full suite with -g 0 1 2 gives
    722 passed, 0 failed.

Also checked with NVHPC 24.5 (nvcr.io/nvidia/nvhpc:24.5-devel-cuda_multi-ubuntu22.04, the CI image, --gpu mp, MPI, 2x A100 visible):

  • master: 4 passed, 2 failed, twice (AFBACA70, 2440B4AE). On 24.5 rank 1 aborts at step 1 with
    "HX_CU_CALL_CHECK(p_cuStreamSynchronize(stream[dev]))" rather than CUDA_ERROR_ILLEGAL_ADDRESS.
  • this change: 6 of 6 pass, twice.
  • The standalone reproducer fails on 24.5 too (CUDA_ERROR_INVALID_CONTEXT on device 1) and passes with the explicit map.

Acknowledgement

  • I confirm this PR meets the above expectations and reflects my own understanding and real-world context.

Since MFlowCode#1821, the Phoenix NVHPC gpu-omp lane intermittently fails
3D -> 2 MPI Ranks -> IBM Sphere (AFBACA70) and
3D -> 2 MPI Ranks -> IBM Moving Sphere -> ib_neighborhood_radius=2 (2440B4AE)
with "call to cuMemcpyDtoHAsync returned error 700 (CUDA_ERROR_ILLEGAL_ADDRESS)"
at step 1, on master and unrelated PRs. It fails whenever the two ranks see
more than one GPU, so rank 1's OpenMP default device is 1; it passes when they
share a GPU, which is why retries sometimes succeed.

compute-sanitizer pins it to an out-of-bounds atomic at the end of the
s_ibm_correct_state ghost-point loop (m_ibm.fpp:598, launched at :345): the
reduction(+:n_not_converged, n_ill_posed) that MFlowCode#1821 added. A standalone
nvfortran 25.11 program reproduces it outside MFC: a multi-variable scalar
reduction on a target teams loop run on default device 1 fails with
CUDA_ERROR_ILLEGAL_ADDRESS when device 0's CUDA context is current (as UCX
leaves it after MPI_Init) and with CUDA_ERROR_INVALID_CONTEXT when none is.
NVHPC allocates the implicitly mapped reduction storage in the current CUDA
context instead of on the default device. Mapping the reduction variables
explicitly with map(tofrom:) avoids it; m_bubbles_EL already pairs its two
reductions with copy= of the same variables.

Emit map(tofrom:) for the reduction variables in OMP_PARALLEL_LOOP on NVHPC,
skipping any already listed in copy. This covers all six reduction loops
without one (m_chemistry, m_collisions, m_data_output, m_ibm,
m_pressure_relaxation, m_time_steppers). Other compilers and OpenACC are
unchanged: the Fypp output is identical apart from those six directives.

Verified on 3x A100 with NVHPC 25.11 (--gpu mp, MPI, release):
- master: the six 2 MPI Ranks tests with -g 0 1 give 4 passed, 2 failed
  (AFBACA70, 2440B4AE: memory access fault by GPU); direct runs with both
  GPUs visible fault 5 of 5 times.
- this change: 6 of 6 pass, three times; the full suite with -g 0 1 2 gives
  722 passed, 0 failed.
@sbryngelson
sbryngelson marked this pull request as ready for review October 11, 2026 02:29
Copilot AI balanced review requested due to automatic review settings October 11, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sbryngelson
sbryngelson merged commit 7ce754f into MFlowCode:master Oct 11, 2026
23 of 30 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T02:32:01.014020Z 615eabf Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/common/include/omp_macros.fpp 380 +13
Directory Lines Diff
common 10461 +13
total 47439 +13

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 615eabf

Files changed:

  • 1
  • src/common/include/omp_macros.fpp

Findings:
No issues found. Checked in step 4: src/common/include/omp_macros.fpp (OMP_PARALLEL_LOOP hunk, against existing reduction= call sites with nested lists and multi-line args, and the copy= overlap in m_bubbles_EL.fpp). Low-confidence note only: OMP_PARALLEL (non-loop) is not given the same explicit reduction map, but no GPU_PARALLEL(... reduction=...) call sites exist today.

@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.75%. Comparing base (a6add01) to head (615eabf).
⚠️ Report is 9 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2018   +/-   ##
=======================================
  Coverage   61.75%   61.75%           
=======================================
  Files          86       86           
  Lines       22787    22787           
  Branches     3357     3357           
=======================================
  Hits        14073    14073           
  Misses       6225     6225           
  Partials     2489     2489           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sbryngelson
sbryngelson deleted the fix/nvhpc-omp-reduction-map branch October 12, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants